# -*- coding: utf-8 -*-
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QSizePolicy, QLabel, QPushButton, QSpacerItem, QComboBox
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QLineEdit
from PyQt5.QtCore import Qt,  QSize, QMetaObject, QCoreApplication


class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(300, 180)
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
        Form.setSizePolicy(sizePolicy)
        Form.setFixedSize(QSize(280, 180))
        Form.setWindowFlags(Qt.WindowCloseButtonHint)
        # 设置窗口无边框
        # Form.setWindowFlags(Qt.FramelessWindowHint)
        Form.setStyleSheet(
            # 设置整体窗口样式
            ".QWidget#Form{"
            "background-color: white;"
            "}"
            #设置输入框样式
            "QLineEdit{"
            "font: 10pt \"微软雅黑\";"
            "border-style: solid;"
            "border-width: 1px;"
            "border-color: #6B8E23;"
            "border-radius: 5px;"
            "background-color: rgb(127, 127, 127, 100)"
            "}"
            #设置下拉框样式
            "QComboBox{"
            "font: 8pt \"微软雅黑\";"
            "border: 1px solid #6B8E23;"
            "border-radius: 5px;"
            "background-color: rgb(127, 127, 127, 30)"
            "}"
            # 设置选择的按钮样式
            ".QPushButton#btn_1{"
            "border-image: url('./static/image/标志1.svg');"
            "}"
            ".QPushButton#btn_2{"
            "border-image: url('./static/image/标志2.svg');"
            "}"
            ".QPushButton#btn_3{"
            "border-image: url('./static/image/标志3.svg');"
            "}"
            ".QPushButton#btn_4{"
            "border-image: url('./static/image/标志4.svg');"
            "}"
            ".QPushButton#btn_5{"
            "border-image: url('./static/image/标志5.svg');"
            "}"
            ".QPushButton#btn_6{"
            "border-image: url('./static/image/圆形6.svg');"
            "}"
            ".QPushButton#btn_7{"
            "border-image: url('./static/image/圆形7.svg');"
            "}"
            ".QPushButton#btn_8{"
            "border-image: url('./static/image/圆形8.svg');"
            "}"
            ".QPushButton#btn_9{"
            "border-image: url('./static/image/圆形9.svg');"
            "}"
            ".QPushButton#btn_10{"
            "border-image: url('./static/image/圆形10.svg');"
            "}"
            ".QPushButton#btn_11{"
            "background-color: rgb(127, 127, 127, 0);"
            "border: 0;"
            "font: \'微软雅黑\';"
            "}"
            # 设置确认、取消按钮样式
            ".QPushButton#pushButton{"
            "background-color: #6B8E23;"
            "border-width: 0px;"
            "color: white;"
            "border-radius: 5px;"
            "}"
            ".QPushButton#pushButton_2{"
            "background-color: #6B8E23;"
            "border-width: 0px;"
            "color: white;"
            "border-radius: 5px;"
            "}"
            )

        # 标记新建的笔记本的颜色，默认为无颜色的图标名称
        self.Add_NoteDir_Color_Flag = "标志5.svg"

        # 标记窗口打开作用是修改还是新建
        self.ifModify = False

        # 上半部分、下半部分组成的全局水平布局
        self.horizontalLayout_3 = QHBoxLayout(Form)
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")

        # 上半部分、下半部分组成的垂直布局
        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.setSpacing(10)
        self.verticalLayout.setObjectName("verticalLayout")

        # 笔记或者笔记本名称输入框
        self.lineEdit = QLineEdit(Form)
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth())
        self.lineEdit.setFixedHeight(25)
        self.lineEdit.setSizePolicy(sizePolicy)
        self.lineEdit.setObjectName("lineEdit")
        self.verticalLayout.addWidget(self.lineEdit)

        # 新建内容标签、新建内容下拉框组成的水平布局
        self.horizontalLayout_4 = QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.horizontalLayout_4.setSpacing(20)

        # 新建内容标签
        font = QFont()
        font.setPointSize(10)
        font.setFamily("微软雅黑")
        self.label_2 = QLabel()
        self.label_2.setFont(font)
        self.label_2.setText("新建内容:")
        self.horizontalLayout_4.addWidget(self.label_2)

        # 新建内容下拉框
        self.comboBox = QComboBox(Form)
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.comboBox.sizePolicy().hasHeightForWidth())
        self.comboBox.setSizePolicy(sizePolicy)
        self.comboBox.setFixedSize(160, 20)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("新建文件夹")
        self.comboBox.addItem("新建笔记")
        self.horizontalLayout_4.addWidget(self.comboBox)
        self.verticalLayout.addLayout(self.horizontalLayout_4)


        # 笔记本颜色标签、颜色标签、空格组成的水平布局
        self.horizontalLayout_1 = QHBoxLayout()
        self.horizontalLayout_1.setObjectName("horizontalLayout_1")
        self.horizontalLayout_1.setSpacing(5)

        # 笔记本颜色标签
        self.label = QLabel()
        self.label.setFont(font)
        self.label.setText("颜色：")
        self.label.setObjectName("lable")
        self.horizontalLayout_1.addWidget(self.label)

        # 笔记本颜色标签
        self.label_1 = QPushButton()
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_1.sizePolicy().hasHeightForWidth())
        self.label_1.setFixedSize(20, 20)
        self.label_1.setStyleSheet("border-image: url('./static/image/标志5.svg');")
        self.label_1.setObjectName("标志5.svg")
        self.horizontalLayout_1.addWidget(self.label_1)

        # 空格
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.horizontalLayout_1.addItem(spacerItem)
        self.verticalLayout.addLayout(self.horizontalLayout_1)

        # 颜色图标组成的水平布局
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setSpacing(4)
        self.horizontalLayout.setObjectName("horizontalLayout")

        # 各种颜色图标
        self.btn_1 = QPushButton()
        self.btn_2 = QPushButton()
        self.btn_3 = QPushButton()
        self.btn_4 = QPushButton()
        self.btn_5 = QPushButton()
        self.btn_5.setText("无")

        self.btn_1.setObjectName("btn_1")
        self.btn_2.setObjectName("btn_2")
        self.btn_3.setObjectName("btn_3")
        self.btn_4.setObjectName("btn_4")
        self.btn_5.setObjectName("btn_5")

        self.btn_1.setFixedSize(20, 20)
        self.btn_2.setFixedSize(20, 20)
        self.btn_3.setFixedSize(20, 20)
        self.btn_4.setFixedSize(20, 20)
        self.btn_5.setFixedSize(20, 20)

        # 各种颜色图标样式设置
        # 图标大小策略
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.btn_1.sizePolicy().hasHeightForWidth())
        sizePolicy.setHeightForWidth(self.btn_2.sizePolicy().hasHeightForWidth())
        sizePolicy.setHeightForWidth(self.btn_3.sizePolicy().hasHeightForWidth())
        sizePolicy.setHeightForWidth(self.btn_4.sizePolicy().hasHeightForWidth())
        sizePolicy.setHeightForWidth(self.btn_5.sizePolicy().hasHeightForWidth())
        
        # 添加至水平布局
        self.horizontalLayout.addWidget(self.btn_1)
        self.horizontalLayout.addWidget(self.btn_2)
        self.horizontalLayout.addWidget(self.btn_3)
        self.horizontalLayout.addWidget(self.btn_4)
        self.horizontalLayout.addWidget(self.btn_5)
        self.verticalLayout.addLayout(self.horizontalLayout)

        # 空格
        spacerItem_1 = QSpacerItem(40, 20, QSizePolicy.Fixed, QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem_1)
        
        # 确认按钮、取消按钮组成的水平布局
        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setSpacing(90)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        
        # 确认按钮
        self.pushButton = QPushButton(Form)
        self.pushButton.setFixedSize(80, 25)
        self.pushButton.setFont(font)
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout_2.addWidget(self.pushButton)
        
        # 取消按钮
        self.pushButton_2 = QPushButton(Form)
        self.pushButton_2.setFixedSize(80, 25)
        self.pushButton_2.setFont(font)
        self.pushButton_2.setObjectName("pushButton_2")
        self.horizontalLayout_2.addWidget(self.pushButton_2)
        self.verticalLayout.addLayout(self.horizontalLayout_2)
        self.horizontalLayout_3.addLayout(self.verticalLayout)

        # 信号动作集合
        # 点击颜色按钮，选择新建的笔记文件夹颜色
        self.btn_1.clicked.connect(self.flag_1)
        self.btn_2.clicked.connect(self.flag_2)
        self.btn_3.clicked.connect(self.flag_3)
        self.btn_4.clicked.connect(self.flag_4)
        self.btn_5.clicked.connect(self.flag_5)
        # 点击添加笔记或者笔记文件夹界面中的下拉框，选择新建的内容是笔记还是笔记本
        self.comboBox.currentIndexChanged.connect(self.addMyNoteOrNoteDirToSelect)
        self.comboBox.activated.connect(self.addMyNoteOrNoteDirToSelect)

        self.retranslateUi(Form)
        QMetaObject.connectSlotsByName(Form)

    """槽函数集合"""

    def flag_1(self):
        self.label_1.setStyleSheet("border-image: url('./static/image/标志1.svg');")
        self.label_1.setObjectName("标志1.svg")
        self.Add_NoteDir_Color_Flag = "标志1.svg"

    def flag_2(self):
        self.label_1.setStyleSheet("border-image: url('./static/image/标志2.svg');")
        self.label_1.setObjectName("标志2.svg")
        self.Add_NoteDir_Color_Flag = "标志2.svg"

    def flag_3(self):
        self.label_1.setStyleSheet("border-image: url('./static/image/标志3.svg');")
        self.label_1.setObjectName("标志3.svg")
        self.Add_NoteDir_Color_Flag = "标志3.svg"

    def flag_4(self):
        self.label_1.setStyleSheet("border-image: url('./static/image/标志4.svg');")
        self.label_1.setObjectName("标志4.svg")
        self.Add_NoteDir_Color_Flag = "标志4.svg"

    def flag_5(self):
        self.label_1.setStyleSheet("border-image: url('./static/image/标志5.svg');")
        self.label_1.setObjectName("标志15.svg")
        self.Add_NoteDir_Color_Flag = "标志15.svg"

        
    def addMyNoteOrNoteDirToSelect(self):

        """
        槽函数
        选择下拉框中的内容，确定是新建笔记还是新建笔记本文件夹
        """

        if self.comboBox.currentText() == "新建笔记":
            self.label_1.setStyleSheet("border-image: url('./static/image/圆形12.svg');")
            self.label_1.setObjectName("圆形12.svg")
            self.Add_NoteDir_Color_Flag = "圆形12.svg"
            self.btn_1.setEnabled(False)
            self.btn_2.setEnabled(False)
            self.btn_3.setEnabled(False)
            self.btn_4.setEnabled(False)
            self.btn_5.setEnabled(False)
        elif self.comboBox.currentText() == "新建文件夹":
            self.label_1.setStyleSheet("border-image: url('./static/image/标志5.svg');")
            self.label_1.setObjectName("标志15.svg")
            self.Add_NoteDir_Color_Flag = "标志15.svg"
            self.btn_1.setEnabled(True)
            self.btn_2.setEnabled(True)
            self.btn_3.setEnabled(True)
            self.btn_4.setEnabled(True)
            self.btn_5.setEnabled(True)

    def retranslateUi(self, Form):
        _translate = QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "添加笔记"))
        self.pushButton.setText(_translate("Form", "确  认"))
        self.pushButton_2.setText(_translate("Form", "取  消"))

    def clasString(self):
        return "MyNoteOrNoteDirWindow"
